﻿using System;
using System.Drawing;
using System.Windows.Forms;
using Tesseract;

namespace BLL
{
    public class DownloadBLL
    {
        public bool SubPicture()
        {
            string path = System.Environment.CurrentDirectory;
            Bitmap bitSize = new Bitmap(315, 205);
            Graphics g = Graphics.FromImage(bitSize);
            Point pl = new Point(370, 230);
            g.CopyFromScreen(pl, new Point(0, 0), bitSize.Size);
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "png|*.png|bmp|*.bmp|gif|*.gif";
            saveFileDialog.FileName = path + @"\F_IMG\imgtp.png";
            bitSize.Save(saveFileDialog.FileName);
            g.Dispose();
            //ImageToText(saveFileDialog.FileName);
            return true;
        }
        public string ImageToText(string imgPath)
        {
            using (var engine = new TesseractEngine(AppDomain.CurrentDomain.BaseDirectory, "eng", EngineMode.Default))
            {
                using (var img = Pix.LoadFromFile(imgPath))
                {
                    using (var page = engine.Process(img))
                    {
                        return page.GetText();
                    }
                }
            }
        }
    }
}
